package com.pengweiwei.androidzygote.main.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.core.app.ActivityCompat;

import com.pengweiwei.androidzygote.R;
import com.pengweiwei.androidzygote.functions.TabActivity;
import com.pengweiwei.androidzygote.functions.base.BaseActFragIndexActivity;
import com.pengweiwei.androidzygote.functions.csutomviews.CustomViewsIndexActivity;
import com.pengweiwei.androidzygote.functions.dialog.DialogIndexActivity;
import com.pengweiwei.androidzygote.functions.theme.ThemeAttrActivity;
import com.pengweiwei.androidzygote.functions.utils.flexbox.FlexboxControllerActivity;
import com.putong35.common.baseactfrag.fragment.BaseFragment;
import com.putong35.common.baseactfrag.view.CenterToolbar;
import com.putong35.common.commonui.citypicker.ChooseCityDialogFragment;
import com.putong35.common.commonui.datetimepicker.DatePickerFragment;
import com.putong35.common.utils.EasyToast;
import com.putong35.easyui.picture.picker.AddPictureDialogFragment;
import com.putong35.easyui.ric.ReleaseImageContentActivity;
import com.putong35.easyui.search.SearchActivity;
import com.putong35.easyui.somedetail.SomeDetailActivity;

import java.util.Calendar;

import butterknife.OnClick;


public class UIIndexFragment extends BaseFragment implements ActivityCompat.OnRequestPermissionsResultCallback{
    public static final String TAG = UIIndexFragment.class.getSimpleName();
    AddPictureDialogFragment diaFrag;

    @OnClick(R.id.btnCustomUI)
    public void onBtnCustomUI() {
        CustomViewsIndexActivity.start(getContext());
    }

    @OnClick(R.id.btnBaseUI)
    public void onBtnBaseUI() {
        Intent intent = new Intent(getActivity(), BaseActFragIndexActivity.class);
        startActivity(intent);
    }


    @OnClick(R.id.btnDatePicker)
    public void onBtnDatePickerClicked() {
        final DatePickerFragment datePickerFragment = new DatePickerFragment();
        datePickerFragment.setCurrentDate(Calendar.getInstance());
        datePickerFragment.setOnDateSelectedListener((year, monthOfYear, dayOfMonth) -> {
            String str = "%1$d年 %2$d月 %3$d日";
            EasyToast.showToast(getActivity(), String.format(str, year, monthOfYear, dayOfMonth));
            datePickerFragment.dismissAllowingStateLoss();
        });
        datePickerFragment.show(getFragmentManager());

    }


    @OnClick(R.id.btnTabActivity)
    public void onBtnTabActivityClicked() {
        TabActivity.start(getActivity());
    }


    @OnClick(R.id.btnDialog)
    public void onBtnDialogClicked() {
        Intent intent = new Intent(getActivity(), DialogIndexActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btnFlexboxController)
    public void onBtnFlexboxControllerClicked() {
        Intent intent = new Intent(getActivity(), FlexboxControllerActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.btnThemeAttr)
    public void onBtnThemeAttrClicked() {
        Intent intent = new Intent(getActivity(), ThemeAttrActivity.class);
        startActivity(intent);
    }


    // region easy ui
    @OnClick(R.id.btnEasyUiSearch)
    public void onBtnEasyUiSearchClicked() {
        SearchActivity.start(getContext());
    }

    @OnClick(R.id.btnEasyUISomeDetail)
    public void onBtnEasyUISomeDetailClicked() {
        SomeDetailActivity.start(getContext());
    }
    @OnClick(R.id.btnReleaseImgContent)

    public void onBtnReleaseImgContentClicked() {
        Intent intent = new Intent(getActivity(), ReleaseImageContentActivity.class);
        startActivity(intent);
    }
    //end region

    @OnClick(R.id.btnChosePic)
    public void btnChosePic() {
        diaFrag.popupChooseDialog();
    }

    @OnClick(R.id.btnCityPicker)
    public void onBtnCityPickerClicked() {
        final ChooseCityDialogFragment chooseCityDialogFragment = new ChooseCityDialogFragment();
        chooseCityDialogFragment.setOnCitySelectedListener((province, city, country) -> {
            String str = "%1$s id=%2$s %3$s id=%4$s %5$s id=%6$s ";
            EasyToast.showToast(getActivity(), String.format(str,
                    province.name,
                    province.id,
                    city.name,
                    city.id,
                    country.name,
                    country.id), Toast.LENGTH_LONG);
            chooseCityDialogFragment.dismissAllowingStateLoss();
        });
        chooseCityDialogFragment.show(getFragmentManager());
    }

    public UIIndexFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment ThemeAttrFragment.
     */
    public static UIIndexFragment newInstance(String param1, String param2) {
        UIIndexFragment fragment = new UIIndexFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = super.onCreateView(inflater, container, savedInstanceState);
        diaFrag = new AddPictureDialogFragment();
        getChildFragmentManager().beginTransaction().add(diaFrag, "diaFrag").commit();

        return view;
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_ui_index, container, false);
        CenterToolbar toolbar = view.findViewById(R.id.toolbar);
        toolbar.setTitle("UI相关");
        return view;
    }

}
